<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=no" />
    <title>BimAngle.com - Trial version</title>
    <link rel="stylesheet" type="text/css"
        href="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/style.min.css">
    <script src="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/viewer3D.min.js"></script>
</head>

<body style="margin:0px">
    <div id="viewer-local"></div>
    <script>
        //ENABLE_DEBUG = false;

        var config = {
            extensions: [
                "Autodesk.Viewing.ZoomWindow",
                "Autodesk.AEC.Minimap3DExtension",
                "Autodesk.AEC.LevelsExtension"
            ],
            disabledExtensions: {
                measure: false,
                section: false,
            },
            memory: {
                limit: 32 * 1024    //32 GB
            }
        };

        var setting = {
            env: 'Local',
            offline: 'true',
            useADP: false,

            //说明: 
            //  这里假设数据部署在当前网页在同一个文件夹路径下;
            //  如果数据部署位置和当前网页文件夹路径不一致，可直接修改 offlineResourcePrefix 为数据的实际部署路径(注意: 尾部不要加斜杠);
            // offlineResourcePrefix: location.href.substring(0, location.href.lastIndexOf('/'))
            offlineResourcePrefix: "http://localhost:3000/sample"
        };

        Autodesk.Viewing.Initializer(setting, function () {
            var element = document.getElementById('viewer-local');
            var viewer = window.viewer = new Autodesk.Viewing.Private.GuiViewer3D(element, config);
            //var viewer = window.viewer = new Autodesk.Viewing.Viewer3D(element, config);

            var startedCode = viewer.start();
            if (startedCode > 0) {
                console.error('Failed to create a Viewer: WebGL not supported.');
                return;
            }

            var documentPath = decodeURIComponent(setting.offlineResourcePrefix + "/manifest-model.json");
            Autodesk.Viewing.Document.load(documentPath, (doc) => {
                doc.downloadAecModelData();

                var viewable = doc.getRoot().getDefaultGeometry();
                var options = {};
                viewer.loadDocumentNode(doc, viewable, options).then(onLoadSuccess);

                viewer.addEventListener(Autodesk.Viewing.TEXTURES_LOADED_EVENT, () => {
                    viewer.getExtension("Autodesk.BimWalk").activate();
                });
            });
        });

        function onLoadSuccess(event) {
            console.log('success');
        }

    </script>
</body>

</html>